<template>
	<view>
		<view class="bj">
			<siginIn :sign_list="sign_list" :sign_rule="sign_rule" :qdjl="qdjl" :tdsy="tdsy" @cksigin="getList">
			</siginIn>
		</view>
		<view class="task">
			<view class="title alpsoftjurnal">
				{{$t('sign.title')}}
			</view>
			<view class="line" v-for="(item, index) in task" :key="index">
				<view class="left">
					<view class="top">
						<view class="name alpsoftjurnal">
							{{ item.name }}
						</view>
						<view class="jd">
							<image src="@/static/jd2.png"></image>
							+{{item.num}}{{item.type == 1?$t('user.gold2'):$t('user.gold1')}}
						</view>
					</view>
					<view class="text alpsoftjurnal">
						{{ item.text}}
					</view>
				</view>
				<view class="button hui alpsoftjurnal" v-if="item.status == 1">{{$t('finish')}}</view>
				<view class="button alpsoftjurnal" v-if="index ==0 && item.status == 0" @click="itemFn">
					{{$t('tofinish')}}
				</view>
				<button class="button alpsoftjurnal" v-if="index == 1"  open-type="share">{{$t('tofinish')}}</button>
			</view>
		</view>
	</view>
</template>
<script>
	import siginIn from '@/components/fanxiao-sign/sigin-in.vue';
import util from '../../utils/util';
	export default {
		components: {
			siginIn
		},
		data() {
			return {
				sign_list: [],
				sign_rule: [],
				qdjl: 0,
				tdsy: 0,
				task: []
			}
		},
		onLoad() {},
		onShow() {
			this.getList();
			this.getSingContinuousDays()
			this.giveCoinRule()
			this.setList()
			util.setNavTitle()
		},
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			var href = '/pages/login/login' + '?fxpid=' + uni.getStorageSync('userinfo').id
			return {
				title: 'Anjur影视',
				path: href
			}
		},
		methods: {
			setList() {
				this.task = [{
					name: this.$t('sign.text1'),
					text: this.$t('sign.desc1'),
					num: 0,
					type: 1,
					status: 0
				}, {
					name: this.$t('sign.text2'),
					text: this.$t('sign.desc2'),
					num: 0,
					type: 2
				}]
			},
			itemFn() {
				uni.request({
					url: this.configs.webUrl + '/api/user/newPersonSing',
					data: {
						token: uni.getStorageSync('userinfo').token
					},
					success: res => {
						console.log(res);
						if (res.data.code == 1) {
							this.giveCoinRule()
						}
						uni.showToast({
							title: res.data.msg,
							mask: true,
							duration: 1000
						})
					}
				});
			},
			getSingContinuousDays() {
				uni.request({
					url: this.configs.webUrl + '/api/user/getSingContinuousDays',
					success: res => {
						console.log(res);
						this.sign_rule = res.data.data.sign_rule
					}
				});
			},
			giveCoinRule() {
				uni.request({
					url: this.configs.webUrl + '/api/user/giveCoinRule',
					data: {
						token: uni.getStorageSync('userinfo').token
					},
					success: res => {
						console.log(res);
						this.task[0].num = res.data.data.new_person_sign
						this.task[1].num = res.data.data.share_reg
						this.task[0].status = res.data.data.is_new_sign
					}
				});
			},
			getList() {
				let this_ = this
				let data = {};
				if (uni.getStorageSync("userinfo")) {
					data.uid = uni.getStorageSync("userinfo").id;
				}
				uni.request({
					url: this.configs.webUrl + '/api/video/zuiju',
					data: data,
					success: data => {
						this.sign_list = data.data.getweek
						this.qdjl = data.data.qdjl
						this.tdsy = data.data.tdsy
					},
					fail: (data, code) => {}
				});
			},
		},
	}
</script>

<style lang="scss" scoped>
	view {
		font-size: inherit;
	}

	.task,
	.bj {
		background: #fff;
		border-radius: 8rpx;
		padding: 20rpx;
		width: 95%;
		margin: 20rpx auto;
	}

	.task {
		.title {
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 600;
			color: #F9762F;
			border-bottom: 1px dashed #F9762F;
			padding-bottom: 10rpx;
		}

		.line {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 20rpx 0;

			.left {
				.top {
					display: flex;
					align-content: center;

					.name {
						font-size: 32rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 600;
						color: #333333;
					}

					.jd {
						display: flex;
						align-items: center;

						image {
							width: 27rpx;
							height: 27rpx;
							margin: 0 10rpx;
						}

						font-size: 28rpx;
						font-family: PingFang SC,
						PingFang SC;
						font-weight: 400;
						color: #FB9D2F;
					}
				}

				.text {
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #AF97A1;
					margin-top: 20rpx;
				}
			}

			.button {
				background: #F75581;
				border-radius: 54rpx;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				padding: 0rpx 30rpx;
				margin: 0;
				line-height: 30px;
				height: 30px;
			}

			.hui {
				background: #ADADAD;
			}
		}
	}
</style>